package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.TolWechatTemplate;
import com.wuliu.system.service.ITolWechatTemplateService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 公众号/小程序消息模板Controller
 * 
 * @author realue
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/system/template")
public class TolWechatTemplateController extends BaseController
{
    @Resource
    private ITolWechatTemplateService tolWechatTemplateService;

    /**
     * 查询公众号/小程序消息模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(TolWechatTemplate tolWechatTemplate)
    {
        tolWechatTemplate.setSysAccount(getSysAccount());
        startPage();
        List<TolWechatTemplate> list = tolWechatTemplateService.selectTolWechatTemplateList(tolWechatTemplate);
        return getDataTable(list);
    }

    /**
     * 导出公众号/小程序消息模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "公众号/小程序消息模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TolWechatTemplate tolWechatTemplate)
    {
        List<TolWechatTemplate> list = tolWechatTemplateService.selectTolWechatTemplateList(tolWechatTemplate);
        ExcelUtil<TolWechatTemplate> util = new ExcelUtil<TolWechatTemplate>(TolWechatTemplate.class);
        util.exportExcel(response, list, "公众号/小程序消息模板数据");
    }

    /**
     * 获取公众号/小程序消息模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tolWechatTemplateService.selectTolWechatTemplateById(id));
    }

    /**
     * 新增公众号/小程序消息模板
     */
    @PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "公众号/小程序消息模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TolWechatTemplate tolWechatTemplate)
    {
        tolWechatTemplate.setSysAccount(getSysAccount());
        return toAjax(tolWechatTemplateService.insertTolWechatTemplate(tolWechatTemplate));
    }

    /**
     * 修改公众号/小程序消息模板
     */
    @PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "公众号/小程序消息模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TolWechatTemplate tolWechatTemplate)
    {
        return toAjax(tolWechatTemplateService.updateTolWechatTemplate(tolWechatTemplate));
    }

    /**
     * 删除公众号/小程序消息模板
     */
    @PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "公众号/小程序消息模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tolWechatTemplateService.deleteTolWechatTemplateByIds(ids));
    }
}
